// ComputerEngine.h

#pragma once

#include "..\Engine\Engine.h"

#include "BitBoardConv.h"

//using namespace System;
//using namespace System::Threading;
//using namespace System::ComponentModel;

namespace CXEngineWrapper {
	using namespace Platform;
	using namespace Windows::System::Threading;
	using namespace concurrency;

	public enum class eCheckersType { CzechCheckers, EnglishCheckers, InternationalCheckers };

	public enum class eBackgroundProcess { PreloadingDatabase, Thinking };

	public delegate void BackgroundProcessDelegate(eBackgroundProcess BackgroundProcessType);
	public delegate void ProgressReportDelegate(int ProgressPercent);
	public delegate void MoveComputedDelegate(OutputBitBoard^ OutputBitBoard);
	public delegate void BackgroundProcessFinishedDelegate();

	public ref class Engine sealed
	{
	public:
		Engine();

		void PreloadEndgameDatabase();
		bool LoadOpeningDatabase(String^ sOpeningPath);
		void TerminateComputer();

		void ComputeMove(eCheckersType checkersType, const Array<Coordinate^>^ board, bool bWhite, int miliseconds, const Array<OutputBitBoard^>^ gameHistory);
			
		// background process reporting
		event BackgroundProcessDelegate^ BackgroundProcessInit;
		event ProgressReportDelegate^ ProgressReport;
		event BackgroundProcessFinishedDelegate^ BackgroundProcessFinished;
		event MoveComputedDelegate^ MoveComputed;

	private protected:

		void TaskLoadEndGameDB();
		void TaskThinking();

		bool _bLoadingEndGameDB;
		task<void> _taskThinking;
		task<void> _taskLoadEndGameDB;	

		// void BackgroundThreadWorker();
		//ManualResetEvent^ _backgroundThreadFinished; 

		String^ _openingFile;
	};
}
